**********************************************
******	Table A16: Trust: Effects in Later Rounds     
**********************************************
	
use "$dir/Data/analysis_main.dta", clear


foreach x of varlist gotcash papc papc_cash cash_postpay cash_announce{
	foreach v of varlist prevw1 prevw2 {
		gen `x'_`v' = `x'*`v'
	}
}

summ totround if pd>0 & pd<. & !mi(divorced) & !mi(n_productivity)
gen dm_totround = totround - r(mean)
gen cash_postpay_dm_totround = dm_totround*cash_postpay


eststo clear


forval i=1/2{
	cap drop *_temp
	foreach x of varlist cash_postpay cash_announce{
		*gen `x'_temp = `x'_prevw`i' // demean 
		summ `x'_prevw`i' if pd>0 & pd<. &!mi(blhrprod) & !mi(n_productivity)
		gen `x'_temp = `x'_prevw`i' - r(mean)
	}

	eststo a`i': reghdfe n_productivity cash_postpay cash_postpay_dm_totround cash_announce cash_postpay_temp blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local int1 "Y"
	qui estadd local int2 "N"
	eststo b`i': reghdfe n_productivity cash_postpay##worksite_id cash_announce cash_postpay_temp blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)
	qui estadd local int2 "Y"
	qui estadd local int1 "N"
}

label var cash_postpay "Cash $\times$ Post-pay" 
label var cash_announce "Cash $\times$ Announcement period "
label var cash_postpay_dm_totround "Cash $\times$ Post-pay $\times$ Total rounds in worksite"
label var cash_announce_temp "Cash $\times$ Announcement period $\times$ Prior rounds in worksite"
label var cash_postpay_temp "Cash $\times$ Post-pay $\times$ Prior rounds in worksite" 


#delimit ;
local tablerow cash_postpay cash_postpay_temp  ;

esttab a2 b2 a1 b1 using "$oa/$t/Table_A16.tex",
    b(3) se booktabs star(* .1 ** .05 *** .01) nonotes nomtitles  
    replace label style(tex) gaps keep(`tablerow') order(`tablerow')
    stats(int1 int2 N, labels("Interactions with number of total rounds in worksite" "Interactions with worksite ID fixed effects" "N: worker-hours") fmt(%10s %10s %9.0fc))
	prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{tabular}
	{@{\extracolsep{4pt}}l*{10}{>{\centering\arraybackslash}m{2.2cm}}@{}} 
	\toprule  	
	\multicolumn{1}{l}{}     &\multicolumn{4}{c}{\textbf{Hourly Production}}  \bigstrut    \\
    \cline{2-5} \addlinespace    
	&\multicolumn{2}{c}{Number of prior rounds} &\multicolumn{2}{c}{Any prior round in worksite}  \\ 
	&\multicolumn{2}{c}{(continuous)} &\multicolumn{2}{c}{(binary)}  \\ 
	\cline{2-3} \cline{4-5} \addlinespace 	") ;
#delimit cr
